

// var url = 'http://localhost:8080/jhtj/';
//
Ext.BLANK_IMAGE_URL = basePath + 'ext/resources/images/default/s.gif';
Ext.SSL_SECURE_URL = basePath + 'ext/resources/images/default/s.gif';

// url += 'JarpListener?className=com.jsepc.jhtj.powerGridDev.ProjectPag';
// url += '&methodName=getSydq';
// url += '&paramCount=1';
// url += '&param_0=' ;

Ext.onReady(function() {
	var tree = new Ext.tree.TreePanel({
		id : 'im-tree',
		title : "",
		loader : new Ext.tree.TreeLoader({
			dataUrl : basePath
					+ 'JarpListener?className=com.jsepc.jhtj.powerGridDev.ProjectPag&methodName=getSydq&paramCount=2&param_0=1111&param_1='
					+ dwdm,

			// alert(baseAttrs);

			baseAttrs : {
				uiProvider : Ext.tree.TreeCheckNodeUI
			}
		}),
		rootVisible : false,
		lines : false,
		iconCls : 'nav',
		checkModel : 'multiple', // 对树的级联多选		onlyLeafCheckable : false,// 对树所有结点都可选		width:320,
		height :390,
		autoScroll : true,
		root : new Ext.tree.AsyncTreeNode({
			text : "江苏省"
		})
//		,
//		buttons : [{
//			text : '保存',
//			handler : function() {
//				saveForm();
//			}
//		}, {
//			text : '返回',
//			handler : function() {
//				guanbi();
//			}
//		}
//		]

	});
	if (dwdm != null && dwdm.length > 0) {
		tree.root.expand(true);

	}
	tree.on("check", function(node, checked) {
			// var id=node.id;
			// var name=node.text;

		});

//	tree.render("tree_id");

	tree.on("beforeload", function(node) {
		node.loader = new Ext.tree.TreeLoader({
			dataUrl : basePath
					+ 'JarpListener?className=com.jsepc.jhtj.powerGridDev.ProjectPag&methodName=getSydq&paramCount=2&param_0='
					+ node.id + '&param_1=' + dwdm,
			baseAttrs : {
				uiProvider : Ext.tree.TreeCheckNodeUI
			}
		});
			// alert(' a ');
			// tree.getNodeById('1200').check(true);
	}, this, true);

	// tree.on('afterload',function(p){
	// alert(' ');
	// tree.getNodeById('1200').check(true);
	// });
	
	var simple = new Ext.Panel({
//		labelWidth : 75, // label settings here cascade unless overridden
		frame : true,
		layout : 'form',
//		bodyStyle : 'padding:5px 5px 0',
		width : '100%',
		height:'100%',
		autoScroll:true,
		items : [tree]
		,
		buttons : [{
			text : '确认',
			handler : function() {
				saveForm();
			}
		}, {
			text : '返回',
			handler : function() {
				guanbi();
			}
		}]
		});
		
//	simple.render("tree_id");
	 var viewport = new Ext.Viewport({
//             layout:'border',
             height:'100%',
             width:'100%',
             items:[simple]});
             
	function guanbi() {
		window.returnValue = null;
		window.close();
	}

	function saveForm() {
		var lst = tree.getChecked();
		var lst1 = tree.nodes;
		// alert(lst1);
		var dwmc = "";
		var dwdm = "";

		for (var i = 0; i < lst.length; i++) {
			var node = lst[i];
			dwdm += "," + node.id;
			dwmc += "," + node.text;
		}
		if (lst.length > 0) {
			// alert(dwdm.substring(1,dwdm.length));
			// alert(dwmc);
			window.returnValue = dwdm.substring(1, dwdm.length) + "&"
					+ dwmc.substring(1, dwmc.length);
		}
		window.close();
	}
});